package com.leo.ibatis.demo.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.leo.ibatis.demo.domain.Inventory;

public class InventoryValidator implements Validator {

	@SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
		return Inventory.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "itemid", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "qty", "required");
	}

}
